package lanqiaoMoNiC;

import java.util.Scanner;

public class G {
	static int arr[][], u[], v[];
	static int n, ans;
	static boolean bo[][], vis[];

	private static void init() {
		arr = new int[10][10];
		arr[1][3] = 2;
		arr[1][7] = 4;
		arr[1][9] = 5;
		arr[2][8] = 5;
		arr[3][7] = 5;
		arr[3][9] = 6;
		arr[4][6] = 5;
		arr[7][9] = 8;
		for (int i = 1; i <= 9; i++)
			for (int j = 1; j < i; j++)
				arr[i][j] = arr[j][i];

	}

	private static boolean isOk() {
		boolean flag = true;
		for (int i = 1; i <= n; i++) {
			flag = bo[u[i]][v[i]] || bo[v[i]][u[i]];
			if (!flag)
				return false;
		}
		return true;
	}

	private static void dfs(int u, int count) {
		if (count >= 4) {
			if (isOk())
				ans++;
		}
		for (int i = 1; i <= 9; i++)
			if (!vis[i])
				if (vis[arr[u][i]]) {
					vis[i] = true;
					bo[u][i] = true;
					dfs(i, count + 1);
					vis[i] = false;
					bo[u][i] = false;
				}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner reader = new Scanner(System.in);
		n = reader.nextInt();
		u = new int[n + 1];
		v = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			u[i] = reader.nextInt();
			v[i] = reader.nextInt();
		}
		init();
		ans = 0;
		for (int i = 1; i <= 9; i++) {
			bo = new boolean[10][10];
			vis = new boolean[10];
			vis[0] = true;
			vis[i] = true;
			dfs(i, 1);

		}
		System.out.println(ans);
		reader.close();
	}
}
